package nige.utils;

import java.util.Vector;

public class Characters {

	public static String[] split(String sentence,String reg) {
		String chaine = sentence+reg;
		Vector result = new Vector();
		try {
			while(chaine.length()>0) {
				String element = chaine.substring(0,chaine.indexOf(reg));
				chaine = chaine.substring(chaine.indexOf(reg)+1,chaine.
						length());
				element = replaceAll(element,reg,"");
				if(element.length()>0) {
					result.addElement(element);
				}
			}
		}
		catch(Exception e) {
			System.out.println("characters.split : "+e);
		}
		String[] s = new String[result.size()];
		for(int i=0;i<s.length;i++) {
			s[i] = (String)result.elementAt(i);
		}
		return s;
	}
	
	public static String replaceAll(String sentence,String reg,String rep) {
		String chaineFinal = sentence;
		if(rep.indexOf(reg)>0) {
			return null;
		}
		while(chaineFinal.indexOf(reg)>-1) {
			chaineFinal = chaineFinal.substring(0,chaineFinal.indexOf(reg))
				+rep+
				chaineFinal.substring(chaineFinal.indexOf(reg)+reg.length()
						,chaineFinal.length());
		}
		return chaineFinal;
	}
}
